package com.xsf.pay.common.inteceptor;

import cn.hutool.core.collection.ListUtil;
import com.xsf.pay.common.resolver.UserParamResolver;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;


/**
 * 拦截器配置
 *
 * @author 18961
 */
@Slf4j
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Resource
    private LogInterceptor logInterceptor;
    @Resource
    private LoginInterceptor loginInterceptor;
    @Resource
    private ApiIdempotentInterceptor apiIdempotentInterceptor;
    @Resource
    private UserParamResolver userParamResolver;
    @Value("${excludePath}")
    private String excludePath;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logInterceptor);
        registry.addInterceptor(loginInterceptor)
                //设置不过滤接口
                .excludePathPatterns(ListUtil.list(false, excludePath.split(",")));
        registry.addInterceptor(apiIdempotentInterceptor);
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(userParamResolver);
    }
}
